#include "ActionInterval.h"
#include "T_Node.h"
#include "T_Scene.h"

ActionInterval *ActionInterval::create(float dur,ActionCallback c){
	ActionInterval *ret=new ActionInterval();
	ret->setDuration(dur);
	ret->addOnDoneCallback(c);
	return ret;
}

bool ActionInterval::init(T_Node *node){
	if(NULL==node){
		return false;
	}
	setTarget(node);
	m_TimeElapsed=0;
	return true;
}

void ActionInterval::startWithTarget(T_Node *node){
	init(node);
	T_Scene *scene=node->getScene();
	if(NULL==scene)return;
	scene->getActionPool().add(this);
}

void ActionInterval::setDuration(float secs){
	m_Duration=secs<0?0:secs;
}

bool ActionInterval::isDone()const{
	return m_TimeElapsed>=m_Duration;
}

void ActionInterval::update(int dt){
	m_TimeElapsed+=dt;
}